<template>
  <div v-if="info" class="container">
    <div class="title">{{ info.describe }}</div>
    <div class="time">发表时间：{{ info.created_at.date.split(" ")[0] }}</div>
    <div class="content" v-html="info.content"></div>
    <div v-if="info.commodity && info.commodity.id" class="dynamic-detail">
      <div v-if="!showItem">
        <div @click="showItem = true" class="video-item">
          <img
            style="height:0.48rem;margin-right:0.2rem;"
            src="@/assets/kll/che.png"
            alt=""
          />文章同款<img
            style="height:0.48rem;margin-left:0.2rem;"
            src="@/assets/new-icon/查看全部箭头.png"
            alt=""
          />
        </div>
      </div>
      <div
        class="item-panel"
        @click="$router.push('/item-detail/' + info.commodity.id)"
        v-else
      >
        <div class="title">
          <div class="left">文章同款</div>
          <div @click.stop="showItem = false" class="right">×</div>
        </div>
        <div class="item-detail">
          <div class="img">
            <img :src="info.commodity.img_show" alt="" />
          </div>
          <div class="item-name">{{ info.commodity.name }}</div>
          <img src="@/assets/kll/chakan.png" class="watch" alt="" />
        </div>
      </div>
    </div>
    <score-mask
      v-if="showMask"
      text="今日观看文章获得"
      :score="integral_rule.watch_article_point"
      @close="showMask = false"
      @finish="getPoint"
    ></score-mask>
  </div>
</template>

<script>
import scoreMask from "./component/score-mask";
import { getArticleDetail } from "@/api/dynamics";
import { getDailyPoint } from "@/api/profile";
import { mapState } from 'vuex'
export default {
  name: "",
  props: [""],
  data() {
    return {
      showItem: false,
      showMask: false,
      info: null,
      missionInterval: null
    };
  },

  computed: {
    ...mapState({
      integral_rule: state => state.app.integral_rule
    })
  },

  watch: {},

  methods: {
    getPoint() {
      getDailyPoint({ genre: "works" }).then(res => {
        if (res.status === 200) {
          this.$dialog.toast({
            mes: "领取成功",
            timeout: 1500,
            icon: "success"
          });
          this.showMask = false;
        }
      });
    }
  },
  beforeRouteLeave(to, from, next) {
    clearTimeout(this.missionInterval);
    next();
  },
  created() {
    getArticleDetail({ id: this.$route.query.id }).then(res => {
      if (res.status === 200) {
        this.info = res.data.data;
        // if (this.info.points !== 1) {
          this.missionInterval = setTimeout(() => {
            this.showMask = true;
          }, 50 * 1000);
        // }
      }
    });
  },

  components: {
    scoreMask
  }
};
</script>
<style lang="less" scoped>
.container {
  padding: 0.8rem 3.2%;
  background: #fff;
  overflow: auto;
  .title {
    color: #333;
    font-size: 0.68rem;
    font-weight: bold;
  }
  .time {
    color: #999;
    font-size: 0.52rem;
    margin: 0.6rem 0;
  }
  .content {
    font-size: 0.64rem;
    color: #666;
  }
  .dynamic-detail {
    position: fixed;
    left: 0.4rem;
    bottom: 2rem;
    color: #fff;
    font-size: 0.52rem;
    .video-item {
      background: rgba(5, 5, 5, 0.661);
      border-radius: 0.12rem;
      padding: 0.1rem 0.25rem;
      display: flex;
      align-items: center;
    }
    .item-panel {
      background: #fff;
      border-radius: 0.12rem;
      padding: 0.4rem;
      width: 8rem;
      box-shadow: 0px 0.08rem 0.6rem 0.06rem rgba(189, 189, 189, 0.29);
      .title {
        font-size: 0.54rem;
        color: #999;
        display: flex;
        justify-content: space-between;
        padding-bottom: 0.3rem;
        .right {
          font-size: 0.64rem;
          width: 2rem;
          text-align: right;
        }
      }
      .item-detail {
        display: flex;
        position: relative;
        .img {
          height: 2rem;
          width: 2rem;
          border-radius: 0.12rem;
          background: #dfdfdf;
          margin-right: 0.1rem;
          img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
        .item-name {
          width: calc(100% - 2.1rem);
          font-size: 0.55rem;
          color: #333;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          overflow: hidden;
          -webkit-line-clamp: 2;
          line-height: 0.75rem;
          height: 1.5rem;
        }
        .watch {
          position: absolute;
          right: 0;
          bottom: 0;
        }
      }
    }
  }
}
</style>
